<template>
	<view>
		<!-- 没加入地址时是按钮  加入后是详细地址 -->
		<view class="address-show-box" v-if="JSON.stringify(address) == '{}'">
			<button type="primary" @click="getAddress">请选择收货地址+</button>
		</view>
		
		<view class="address-info-box" v-else>
			<view class="user-info">
				<view class="left">
					<view class='user-name'>收货人：<text>{{address.userName}}</text></view>
				</view>
				<view class="right">
					<view class='user-phone'>电话：<text>{{address.telNumber}}</text></view>
					<uni-icons type="right" size="18"></uni-icons>
				</view>
			</view>
			<view class="user-address">
				<view class='address'>收货地址：<text>{{addressStr}}</text></view>
			</view>
		</view>
		
		<image src="/static/cart_border@2x.png" class="img" mode=""></image>
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from "vuex";
	export default {
		name:"my_address",
		data() {
			return {
				// address:{}
			};
		},
		created() {
			console.log(this.$store);
			// this.getAddress()
		},
		computed:{
			...mapState('user_m',['address']),
			...mapGetters('user_m',['addressStr'])
			// addressStr(){
			// 	return this.address.provinceName + this.address.cityName + this.address.countyName + this.address.detailInfo
			// }
		},
		methods:{
			...mapMutations('user_m',['updateAddress']),
			async getAddress(){
				const [err,succ] = await uni.chooseAddress().catch(err=>err);
				console.log(succ);
				if(err === null && succ.errMsg == 'chooseAddress:ok'){
					// this.address = succ;
					this.updateAddress(succ);
				}else{
					return uni.$showMsg()
				}
			}
		}
	}
</script>

<style lang="scss">
	
.address-show-box{
	height: 90px;
	display: flex;
	justify-content: center;
	align-items: center;
	button{
		font-size: 14px;
	}
}

.address-info-box{
	font-size: 14px;
	padding: 0 5px;
	margin-top: 10px;
	.user-info{
		height: 40px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.left{
			
			.user-name{
				
			}
		}
		.right{
			display: flex;
			flex-wrap: nowrap;
			.user-phone{
				
			}
		}
	}
	
	.user-address{
		height: 40px;
		.address{
			
		}
	}
}

.img{
	width: 100%;
	height: 5px;
	display: block;
}
</style>
